USE [influenza]
GO

/****** Object:  StoredProcedure [dbo].[SP_RptOpTomaMuestra]    Script Date: 03/12/2010 09:59:33 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[SP_RptOpTomaMuestra]
@param varchar(100)

as
Begin
declare 
@dias int,
@qry varchar(8000)

Set @qry='
select datediff(DAY,b.fSintoma_inicial,m.fToma) as dias
from dat_registro b
inner join aux_muestras m on (b.id_principal=m.id_principal)'
if @param >0
begin
	Set @qry=@qry+' Where nLaboratorio='+@param
end
Set @qry=@qry+' order by dias'

exec (@qry)

end
GO

